function [x,y]=circle_flow_g(bs,s)
%CARDG Geometry File defining the geometry of a cardioid.

%       L. Langemyr 1-27-95.
%       Copyright 1994-2003 The MathWorks, Inc.
%       $Revision: 1.1.1.1 $  $Date: 2011-06-14 06:35:42 $

nbs=8;

if nargin==0
  x=nbs;
  return
end

d=[     0   0   0   0   0   0   0   0;
        1   1   1   1   1   1   1   1;
        0   0   0   0   0   0   0   0;
        1   1   1   1   1   1   1   1];

if nargin==1
  x=d(:,bs);
  return
end


x=zeros(size(s));
y=zeros(size(s));
[m,n]=size(bs);
if m==1 && n==1,
  bs=bs*ones(size(s)); % expand bs
elseif m~=size(s,1) || n~=size(s,2),
  error('PDE:cardg:SizeBs', 'bs must be scalar or of same size as s.');
end

if ~isempty(s)

% boundary segment 1
ii=find(bs==1);
x(ii)=2+cos((pi/2)*s(ii));
y(ii)=2+sin((pi/2)*s(ii));

% boundary segment 2
ii=find(bs==2);
x(ii)=2+cos((pi/2)*s(ii)+(pi/2));
y(ii)=2+sin((pi/2)*s(ii)+(pi/2));

% boundary segment 3
ii=find(bs==3);
x(ii)=2+cos((pi/2)*s(ii)+pi);
y(ii)=2+sin((pi/2)*s(ii)+pi);

% boundary segment 4
ii=find(bs==4);
x(ii)=2+cos((pi/2)*s(ii)+(3*pi/2));
y(ii)=2+sin((pi/2)*s(ii)+(3*pi/2));

% boundary segment 5
ii=find(bs==5);
if length(ii)
x(ii)=interp1([d(1,5),d(2,5)],[22 22],s(ii));
y(ii)=interp1([d(1,5),d(2,5)],[4 0],s(ii));
end

% boundary segment 6
ii=find(bs==6);
if length(ii)
x(ii)=interp1([d(1,6),d(2,6)],[22 0],s(ii));
y(ii)=interp1([d(1,6),d(2,6)],[0 0],s(ii));
end

% boundary segment 7
ii=find(bs==7);
if length(ii)
x(ii)=interp1([d(1,7),d(2,7)],[0 0],s(ii));
y(ii)=interp1([d(1,7),d(2,7)],[0 4],s(ii));
end

% boundary segment 8
ii=find(bs==8);
if length(ii)
x(ii)=interp1([d(1,8),d(2,8)],[0 22],s(ii));
y(ii)=interp1([d(1,8),d(2,8)],[4 4],s(ii));
end

end
